#pragma once
#include <thread>
#include <mutex>
#include <condition_variable>
#include <queue>

// 异步写日志的队列
template <typename T>
class LockQueue
{
private:
    std::queue<T> m_queue;
    std::mutex m_mutex;
    std::condition_variable m_conditionvariable;

public:
    void Push(T &t)
    {
        std::lock_guard<std::mutex> lck(m_mutex);
        m_queue.push(t);
        m_conditionvariable.notify_one(); // 只有一个出队线程
    }

    T Pop()
    {
        std::unique_lock<std::mutex> lck(m_mutex);

        while (m_queue.empty())
        {
            m_conditionvariable.wait(lck);
        }
        T t = m_queue.front();
        m_queue.pop();
        return t;
    }
};
